package me.numark.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import com.umeng.analytics.MobclickAgent;

import me.numark.R;
import me.numark.fragments.ProfileFragment;
import me.numark.utils.Global;


public class ProfileActivity extends BaseActivity {

    public static final String EXTRA_UID = "uid";
    int uid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        uid = getIntent().getIntExtra(EXTRA_UID, Global.getCurrentUid());
        Bundle args = new Bundle();
        args.putInt(ProfileFragment.USER_ID, uid);
        Fragment fragment = ProfileFragment.instantiate(this,
                ProfileFragment.class.getName(), args);
        getSupportFragmentManager().beginTransaction().add(R.id.fragment, fragment).commitAllowingStateLoss();
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        Global.currentProfileUid = uid;
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
        Global.currentProfileUid = 0;
    }

    public static void openProfile(Context context, int uid) {
        if (uid == Global.currentProfileUid)
            return;
        Intent intent = new Intent(context, ProfileActivity.class);
        intent.putExtra(ProfileActivity.EXTRA_UID, uid);
        context.startActivity(intent);
    }
}
